package ru.alperez.model;

import ru.alperez.util.NmeaParser;

public class LastFixState {
	private boolean fixed;
	private int nSat;
	private long sysTime;
	
	public LastFixState() {
		fixed = false;
		sysTime = System.currentTimeMillis();
	}
	
	public LastFixState(String nmeaGPGGA) {
		try{
			String[] values = nmeaGPGGA.split("[,*]");
			if (Integer.parseInt(values[6]) > 0) {
				fixed = true;
				nSat = Integer.parseInt(values[7]);
			} else {
				fixed = false;
				nSat = 0;
			}
		} catch (Exception e) {
			fixed = false;
			nSat = 0;
		}
		sysTime = System.currentTimeMillis();
	}
	
	public boolean update (String nmeaGPGGA) {
		try{
			String[] values = nmeaGPGGA.split("[,*]");
			if (Integer.parseInt(values[6]) > 0) {
				fixed = true;
				nSat = Integer.parseInt(values[7]);
			} else {
				fixed = false;
				nSat = 0;
			}
		} catch (Exception e) {
			fixed = false;
			nSat = 0;
		}
		sysTime = System.currentTimeMillis();
		return fixed;
	}
	
	public boolean isFixed() {
		return fixed;
	}
	
	public int getNSat() {
		return nSat;
	}
	
	public long getSysTime() {
		return sysTime;
	}
}
